{extend name='base' /}
{block name='content'}
<body class="login-bg">

<div class="login layui-anim layui-anim-up">
    <div class="message">游戏后台登录</div>
    <div id="darkbannerwrap"></div>

    <form method="post" class="layui-form" id="loginData">
        <input name="username" placeholder="用户名"  type="text" class="layui-input" >
        <hr class="hr15">
        <input name="password" lay-verify="required" placeholder="密码"  type="password" class="layui-input">
        <hr class="hr15">
        <div style="position:relative">
            <input name="captcha" lay-verify="required" placeholder="验证码"  type="text" class="layui-input" >
            <img src="{:captcha_src()}" alt="" width="130px" height="48px" onclick="this.src='{:captcha_src()}?time='+Math.random()" style="position: absolute;right: 1px;top: 1px;">
        </div>
        <hr class="hr15">
        <input value="登录"  style="width:100%;" type="button" onclick="login()" id="loginBtn">


    </form>
</div>

<script>
    function login() {
        var index = layer.load(2);
        $.ajax({
            url:"{:url('login/login')}",
            data:$('#loginData').serialize(),
            dataType:'json',
            type:'post',
            success:function (res) {
                if (res.state){
                    layer.close(index)
                    layer.msg(res.message)
                    setTimeout(function () {
                        location.href=res.url
                    },1000)
                } else{
                    setTimeout(function () {
                        layer.close(index)
                        layer.msg(res.message)

                    },500)

                }
            },
            error:function () {
                setTimeout(function () {
                    layer.close(index)
                    layer.msg('出错了请稍后再试...');
                },500)

            }
        })
    }

    $(document).keydown(function (event) {
        if (event.keyCode == 13) {
            login()
        }
    });

</script>



</body>
{/block}